package com.lonely.web.controller.goods;

import com.lonely.common.core.domain.Tree;
import com.lonely.common.core.domain.api.R;
import com.lonely.goods.domain.dto.material.group.GroupSubmitDTO;
import com.lonely.goods.domain.vo.material.group.MaterialTypeGroupVO;
import com.lonely.goods.service.IMaterialTypeGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author : 黄志标
 * @date: 2025/7/10 10:08
 * @description: 物料类型分组请求处理器
 */
@RestController
@RequestMapping("/goodsManager/material/group")
@Api(tags = "商品管理/物料类型")
public class MaterialTypeGroupController {

    @Autowired
    private IMaterialTypeGroupService materialTypeGroupService;

    /**
     * 获取物料类型分组树
     *
     * @return
     */
    @GetMapping("/getTree")
    @ApiOperation(value = "获取物料类型分组树")
    public R<Tree> getTree() {
        return R.data(this.materialTypeGroupService.getTree());
    }

    /**
     * 创建组
     *
     * @return
     */
    @PostMapping("/addGroup")
    @ApiOperation(value = "创建组")
    public R<Boolean> addGroup(@RequestBody @Valid GroupSubmitDTO submitDTO) {
        this.materialTypeGroupService.addGroup(submitDTO);
        return R.status(true);
    }


    /**
     * 编辑组
     *
     * @return
     */
    @PostMapping("/editGroup")
    @ApiOperation(value = "编辑组")
    public R<Boolean> editGroup(@RequestBody @Valid GroupSubmitDTO submitDTO) {
        this.materialTypeGroupService.editGroup(submitDTO);
        return R.status(true);
    }


    /**
     * 删除指定组
     *
     * @param groupId
     * @return
     */
    @GetMapping("/deleteGroup/{groupId}")
    @ApiOperation(value = "删除指定组")
    public R<Boolean> deleteGroup(@PathVariable("groupId") Long groupId) {
        this.materialTypeGroupService.deleteGroup(groupId);
        return R.status(true);
    }

    /**
     * 获取指定组信息
     *
     * @param groupId
     * @return
     */
    @GetMapping("/getById/{groupId}")
    @ApiOperation(value = "获取指定组信息")
    public R<MaterialTypeGroupVO> getById(@PathVariable("groupId") Long groupId) {
        return R.data(this.materialTypeGroupService.getById(groupId));
    }
}
